package com.lw.kotlin_mvvm_master.view.refresh

import android.os.Bundle
import com.lw.common.base.BaseActivity
import com.lw.kotlin_mvvm_master.databinding.ActivityRefreshBinding
import com.scwang.smart.refresh.layout.api.RefreshLayout
import com.scwang.smart.refresh.layout.listener.OnRefreshLoadMoreListener

class SmartRefreshActivity : BaseActivity<ActivityRefreshBinding>() {
    override fun initView(savedInstanceState: Bundle?) {
        mBinding.refreshLayout.setOnRefreshLoadMoreListener(object : OnRefreshLoadMoreListener {
            override fun onRefresh(refreshLayout: RefreshLayout) {
                refreshLayout.layout.postDelayed({
                    refreshLayout.finishRefresh()
                    refreshLayout.resetNoMoreData() //setNoMoreData(false);//恢复上拉状态
                }, 2000)
            }

            override fun onLoadMore(refreshLayout: RefreshLayout) {
                refreshLayout.layout.postDelayed({
                    refreshLayout.finishLoadMore()
//                    refreshLayout.finishLoadMoreWithNoMoreData()
//                    if (mAdapter.getCount() > 12) {
//                        Toast.makeText(baseContext, "数据全部加载完毕", Toast.LENGTH_SHORT).show()
//                        refreshLayout.finishLoadMoreWithNoMoreData() //设置之后，将不会再触发加载事件
//                    } else {
//                        mAdapter.loadMore(loadModels())
//                        refreshLayout.finishLoadMore()
//                    }
                }, 1000)
            }
        })
    }
}